package com.net.xpay.common.manager.impl.partner;

import com.google.common.base.Preconditions;
import com.net.common.annotation.ReadTransactional;
import com.net.common.dao.BasicMapper;
import com.net.common.dao.Page;
import com.net.common.manager.AbstractManager;
import com.net.xpay.common.dao.partner.PartnerSettleLogMapper;
import com.net.xpay.common.domain.partner.PartnerSettleLog;
import com.net.xpay.common.manager.partner.PartnerSettleLogManager;
import com.net.xpay.common.model.PartnerUnionSettleLogResultModel;
import com.net.xpay.common.model.search.PartnerSettleLogSearchModel;
import com.net.xpay.common.model.search.PartnerUnionSettleLogSearchModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;


@Component
@ReadTransactional
public class PartnerSettleLogManagerImpl extends AbstractManager<PartnerSettleLog> implements PartnerSettleLogManager{

    @Autowired
    private PartnerSettleLogMapper mapper;


    @Override
    protected BasicMapper<Long, PartnerSettleLog> getMapper() {
        return mapper;
    }

    @Override
    public List<PartnerSettleLog> search(PartnerSettleLogSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        Page page = new Page(searchModel);
        page.addOrder("id", "desc");
        return nonEmptyList(mapper.search(searchModel, page));
    }

    @Override
    public long searchCount(PartnerSettleLogSearchModel searchModel) {
        return mapper.searchCount(searchModel);
    }

    @Override
    public List<PartnerSettleLog> list(PartnerSettleLogSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        return nonEmptyList(mapper.list(searchModel));
    }

    @Override
    public List<PartnerUnionSettleLogResultModel> searchUnion(PartnerUnionSettleLogSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        Page page = new Page(searchModel);
        page.addOrder("id", "desc");
        page.addOrder("create_time", "desc");
        return mapper.searchUnion(searchModel, page) == null ? new ArrayList<>() : mapper.searchUnion(searchModel, page) ;
    }

    @Override
    public long searchUnionCount(PartnerUnionSettleLogSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        return mapper.searchUnionCount(searchModel);
    }
}
